using System;
using System.Text;

namespace IBNet
{
   /// <summary>
   /// Option Class - uses default constructors for creating an option contract.
   /// </summary>
   /// <seealso cref="Contract"/>
   public class Option : Contract
   {
      /// <summary>
      /// Creates an Option Contract
      /// </summary>
      /// <param name="equitySymbol">Symbol of the equity.</param>
      /// <param name="optionSymbol">Symbol of the option for the underlying equity.</param>
      /// <param name="expiry">Option Expiration String.</param>
      /// <param name="right">Option Right (Put or Call).</param>
      /// <param name="strike">Option Strike Price.</param>
      public Option(string equitySymbol, string optionSymbol, string expiry,
         RightType right, decimal strike)
         : base(0, equitySymbol, SecurityType.Option, expiry, strike,
                right, "100", "SMART", "USD", optionSymbol, "SMART", null, null)
      {
      }

      /// <summary>
      /// Creates an Option Contract
      /// </summary>
      /// <param name="equitySymbol">Symbol of the equity. See <see cref="Contract.Symbol"/>.</param>
      /// <param name="optionSymbol">Symbol of the option for the underlying equity. See <see cref="Contract.LocalSymbol"/>.</param>
      /// <param name="year">Option Expiration Year. See <see cref="Contract.Expiry"/>.</param>
      /// <param name="month">Option Expiration Month. See <see cref="Contract.Expiry"/>.</param>
      /// <param name="right">Option Right (Put or Call). See <see cref="Contract.RightType"/>.</param>
      /// <param name="strike">Option Strike Price. See <see cref="Contract.Strike"/>.</param>
      public Option(string equitySymbol, string optionSymbol, int year, int month,
         RightType right, decimal strike)
         : base(0, equitySymbol, SecurityType.Option, null, 
                strike, right, "100", "SMART", "USD", optionSymbol, "SMART", null, null)
      {
         base.Expiry = CreateExpiryString(year, month);
      }

      private static string CreateExpiryString(int year, int month)
      {
         string expiry = 
            new StringBuilder().AppendFormat("{0:0000}{1:00}", year, month).ToString();
         return expiry;
      }
   }
}
